/**
 * 
 */
package dms.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 李健
 *
 */
public class DateFormatUtil {

	public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
	public static final String DATE_PATTERN = "yyyy-MM-dd";
	
	public static Date parseDate(String source) throws ParseException {
		if (source == null || source.length() == 0) {
			return null;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
		Date parsedDate = null;
		
		try {
			parsedDate = sdf.parse(source);
		} catch (ParseException e) {
			throw new ParseException("日期格式不正确", e.getErrorOffset());
		}
		return parsedDate;
	}
	
	public static Date parseDateTime(String source) throws ParseException {
		if (source == null || source.length() == 0) {
			return null;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(DATETIME_PATTERN);
		Date parsedDate = null;
		
		try {
			parsedDate = sdf.parse(source);
		} catch (ParseException e) {
			throw new ParseException("日期格式不正确", e.getErrorOffset());
		}
		return parsedDate;
	}
}
